home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 25 / AACD 25.iso / AACD / Online / IB-TablePrint / Table.gc < prev    next >
Encoding:
Gui4CLI script  |  2001-08-17  |  10.8 KB  |  521 lines

  1. G4C
  2.  
  3. WINBIG 0 10 600 220 Table.gc
  4. ; Table.gc V1.05 17 Aug 2001 
  5. ; Author: Joseph Duchâtelet jduchatelet @arcadis.be
  6. WINTYPE 11110001
  7. RESINFO 8 640 256
  8.  
  9. xONLOAD Fl2Tr 2File
  10.  Gosub #this Default
  11.  
  12. xONRELOAD
  13.  Gosub #this Default
  14.  
  15. xROUTINE Default
  16.  SetGad #this 1 HIDE
  17.  SetGad #this 3 HIDE
  18.  Extract #this GUIPATH mypath
  19.  IFEXISTS ASSIGN ~guitb:
  20.     Assign guitb: '$mypath' ; mypath :=> path of the drawer Assign.gc is in
  21.      ;EzReq 'Do you want to add the assign to user_startup ?' 'ok|no' var
  22.  ENDIF
  23.  cd guitb:
  24.  GuiLoad guitb:Table.Cfg
  25.  IF $.TbCfg_Help = ON
  26.     GuiLoad guitb:Table.hlp
  27.  ENDIF
  28.  NwWdth = 450 ; new max table width
  29.  InitReq = YES
  30.  IF $Fl2Tr = ''
  31.     GuiOpen #this
  32.     IF  $InitReq = YES
  33.         ReqFile 0 0 240 200 "Get HTML file to transform " LOAD Fl2Tr #guitb:2Transform/#?
  34.         CLI 'Faststrip $Fl2Tr 13 10'
  35.         LVUse #this 2
  36.         Extract Fl2Tr FILE FlNm
  37.         LVChange $Fl2Tr
  38.     ENDIF
  39.     
  40.  ELSE
  41.     LVUse #this 2
  42.     IF $2File = ''
  43.         2File = $Fl2Tr
  44.     ENDIF
  45.     IFEXISTS FILE $Fl2Tr
  46.         Extract Fl2Tr FILE FlNm
  47.         LVChange $Fl2Tr
  48.         Gosub #this TransformIt
  49.         LVSave $2File
  50.     ELSE
  51.         EzReq "No such file as $Fl2Tr" "ok" var
  52.     ENDIF
  53.  ENDIF
  54.  ChCtr = 0
  55.  
  56.  
  57. xONCLOSE
  58.  Delete env:.Tb#?
  59.  GuiQuit Table.Cfg
  60.  GuiClose Table.hlp
  61.  GuiQuit #this
  62.  
  63. xBUTTON 0 0 60 14 LdHTML ; <<LdHTML>>
  64.  GadHelp "Load HTML source to check and modify"
  65.  ReqFile 0 0 240 200 "Get HTML file to transform " LOAD Fl2Tr #guitb:2Transform/
  66.  IFEXISTS FILE $Fl2Tr
  67.     Extract Fl2Tr FILE FlNm
  68.     LVUse #this 2
  69.     CLI 'Faststrip $Fl2Tr 13 10'
  70.     LVChange $Fl2Tr
  71.     LVUSE #this 1
  72.     LVClear
  73.     LVUse #this 2
  74.  ELSE
  75.     EzReq "No such file as $Fl2Tr" "ok" var
  76.  ENDIF
  77.  
  78. xBUTTON 60 0 60 14 VwImL ; <<VwImL>>
  79.  GadHelp "View Image list"
  80.  Gosub #this ShowImgList
  81.  LVGo first
  82.  IF $LVVar1 = ''
  83.     EzReq "no list, create it ?" "yes|no" var
  84.     IF $var = 1
  85.         Gosub #this ImagesAll
  86.     ENDIF        
  87.  ENDIF
  88.  
  89. xBUTTON 120 0 60 14 VwHTML ; <<VwHTML>>
  90.  GadHelp "View HTML source"
  91.  Gosub #this ShowIt
  92.  
  93.  
  94. xBUTTON 180 0 60 14 "Trsform" ; <<Trsform>>
  95.  GadHelp "Transform the litigious table widths to preset NwWdth = $NwWdth"
  96.  Gosub #this TransformIt
  97.  
  98. xBUTTON 240 0 60 14 "Strip" ; <<Strip>>
  99.  GadHelp "Strip all images"
  100.  IF $$LV.ID = 2
  101.     EZReq "Strip all images, select to strip? " "All|SStr|Stop" var
  102.     If $var = 1
  103.         Gosub #this StripIt
  104.     ELSEIF $var = 2
  105.         Gosub #this ImagesAll
  106.         EzReq "Select the images you want to delete, then hit <<Strip>> again" "ok" var
  107.     ELSEIF $var = 0
  108.         stop
  109.     ENDIF
  110.  ELSE
  111.     Gosub #this DelImgSelect
  112.  ENDIF
  113.  
  114. xROUTINE DelImgSelect ; LV1
  115.  SetGad #this 2 HIDE
  116.  SetGad #this 1 HIDE
  117.  Ctr = 0
  118.  LVMULTI FIRST
  119.  WHILE $$LV.LINE > ''
  120.     ++Ctr
  121.     Img = $LVVar1
  122.     LVUse #this 2
  123.     LVSearch $Img CI FIRST
  124.     RepVar LVVar2 $Img "" CI
  125.     LVUse #this 1
  126.     LVMulti NEXT
  127.  ENDWHILE
  128.  LVDEL SELECTED
  129.  EzReq "Deleted $Ctr images" ok var
  130.  Gosub #this ShowIt
  131.  
  132. xROUTINE ToggleSelect
  133.  Top = $$LV.Top
  134.  SetGad #this $$LV.ID HIDE
  135.  LVGo FIRST
  136.  WHILE $$LV.LINE > ''
  137.     IF $$LV.SEL = 0
  138.         LVMulti ON
  139.     ELSE
  140.         LVMulti OFF
  141.     ENDIF
  142.      LVGo NEXT
  143.  ENDWHILE
  144.  SetGad #this $$LV.ID SHOW
  145.  GadRedraw #this 2 2 2 2 0
  146.  LVMove #$Top
  147.  
  148. xROUTINE ToggleSelect3
  149.  SetGad #this $$LV.ID HIDE
  150.  SelSt.0 = OFF
  151.  SelSt.1 = ON
  152.  LVGo FIRST
  153.  WHILE $$LV.LINE > ''
  154.     ;LVMULTI "$SelSt.$$LV.SEL" ; dos not work
  155.      LVGo NEXT
  156.  ENDWHILE
  157.  SetGad #this $$LV.ID SHOW
  158.  Redraw #this
  159.  
  160.  
  161. xROUTINE ToggleSelect2 ;
  162.  LVGo LAST
  163.  LineLst = $$LV.LINE
  164.  LVMulti FIRST
  165.  IF $$LV.LINE > 0 ; file starts with an unselected block
  166.      Line1 = $$LV.LINE ; begin of next selected block
  167.     LVGo FIRST
  168.     WHILE $$LV.LINE < $Line1
  169.         LVMULTI ON
  170.         LVGo Next
  171.     ENDWHILE
  172.     ; now we are on 1st line of selected block (Line1)
  173.     Gosub #this Sel2Unsel ; till we are on a first unselected line
  174.  ELSE ; first line selected
  175.     LVGo FIRST
  176.     Gosub #this Sel2Unsel ; till we are on a first unselected line
  177.  ENDIF
  178.  
  179.  
  180. xROUTINE Sel2Unsel
  181.  WHILE $$LV.LINE > ''
  182.  AND $$LV.SEL = 1
  183.         LVMulti OFF
  184.         LVGo Next
  185.  ENDWHILE ; unselcted now
  186.  IF $$LV.LINE > ''
  187.      Line0 = $$LV.LINE ; begin of an unselected block
  188.     Gosub #this Unsel2Sel
  189.  ENDIF
  190.  
  191.  
  192. xROUTINE Unsel2Sel
  193.  LVMulti NEXT
  194.  IF $$LV.LINE > $Line0 ; always the case unless there is no selected any more
  195.      Line1 = $$LV.LINE
  196.  ELSE
  197.     Line1 = $LineLst
  198.  ENDIF
  199.  LVGo #$Line0
  200.  WHILE $$LV.LINE < $Line1
  201.         LVMULTI ON
  202.         LVGo Next
  203.  ENDWHILE
  204.  IF $Line1 < $LineLst
  205.     Gosub #this Sel2Unsel
  206.  ENDIF
  207.  
  208.  
  209.  
  210. xROUTINE DelImgNotSelect ; LV1
  211.  SetGad #this 2 HIDE
  212.  SetGad #this 1 HIDE
  213.  Ctr = 0
  214.  LVMULTI FIRST
  215.  WHILE $$LV.LINE > ''
  216.     ++Ctr
  217.     Img = $LVVar1
  218.     LVUse #this 2
  219.     LVSearch $Img CI FIRST
  220.     RepVar LVVar2 $Img "" CI
  221.     LVUse #this 1
  222.     LVMulti NEXT
  223.  ENDWHILE
  224.  LVDEL SELECTED
  225.  EzReq "Deleted $Ctr images" ok var
  226.  Gosub #this ShowIt
  227.  
  228. xROUTINE ImagesAll
  229.  SetGad #this 1 HIDE
  230.  SetGad #this 2 HIDE
  231.  LVUse #this 1
  232.  LVClear
  233.  LVUse #this 2
  234.  SetGad #this 2 HIDE
  235.     Ctr = 0
  236.     LVSearch "<img" CI FIRST
  237.     While $$LV.LINE > ''
  238.         ++Ctr
  239.         PosH = $$Search.Pos
  240.         LVSearch ">" CI NEXT
  241.         PosT = $$Search.Pos
  242.         Lgt = $($PosT - $PosH)
  243.         ImSgmt.$Ctr = $LVVar2[$PosH][$Lgt]
  244.         LVUse #this 1
  245.         LVAdd "$ImSgmt.$Ctr"
  246.         LVUse #this 2
  247.         Line.$Ctr = $$LV.LINE
  248.         PosH.$Ctr = $PosH
  249.         Lgt.$Ctr = $Lgt
  250.         LVSearch "<img" CI NEXT
  251.     EndWhile
  252.  Gosub #this ShowImgList
  253.  
  254. xROUTINE ShowImgList
  255.  SetGad #this 2 HIDE
  256.  SetGad #this 2 HIDE
  257.  SetGad #this 1 SHOW
  258.  Redraw #this
  259.  LVUse #this 1
  260.  
  261. xROUTINE StripIt
  262.  Set BUFFERS 2048
  263.  LVUse #this 2
  264.  SetGad #this 2 HIDE
  265.  Ctr = 0
  266.  LVSearch "<img" CI FIRST
  267.  While $$LV.LINE > ''
  268.     t = $$LV.REC
  269.     While $$SEARCH.POS > ''
  270.         ++Ctr
  271.         CutVar t Cut Char $$SEARCH.POS s
  272.         SearchVar t ">" CI FIRST
  273.         CutVar t Cut Char $($$SEARCH.POS + 1) r
  274.         AppVar s $t
  275.         t = $s
  276.         SearchVar t "<img" CI FIRST
  277.     EndWhile
  278.     LVPut $t
  279.     LVSearch "<img" CI NEXT
  280.  EndWhile
  281.  TotCtr = $($TotCtr + $Ctr)
  282.  EzReq "Stripped $TotCtr images" ok var
  283.  LVUse #this 1
  284.  LVClear
  285.  Gosub #this ShowIt
  286.  Set BUFFERS 1024
  287.  
  288. xBUTTON 300 0 60 14 Save ; <<Save>>
  289.  GadHelp "Save the (transformed?) file"
  290.  IF $$LV.ID = 2
  291.     ;PropFl = 'guitb:Transformed/\#$FlNm '
  292.     ReqFile 0 0 240 200 "Save your file as ? " SAVE FlSv #guitb:Transformed/$FlNm
  293.     IF $FlSv > ''
  294.         LVSave $FlSv
  295.         EzReq "Delete original html file ? " "ok|stop" var
  296.         IF $var = 1
  297.             Delete $Fl2Tr
  298.         ENDIF
  299.      ENDIF
  300.  ELSE
  301.     ReqFile 0 0 240 200 "Save your imagelist as ? " SAVE ImSv #guitb:ImageList/$FlNm
  302.     IF $ImSv > ''
  303.         LVSave $ImSv
  304.      ENDIF
  305.  ENDIF
  306.  
  307. xBUTTON 360 0 20 14 "Al" ; <<Al>>
  308.  GadHelp "Select all selected lines"
  309.  LVMulti ALL
  310.  
  311. xBUTTON 380 0 20 14 "Nn" ; <<Nn>>
  312.  GadHelp "Deselect all selected lines"
  313.  LVMulti NONE
  314.  
  315. xBUTTON 400 0 20 14 "Tg" ;  <<Tg>>
  316.  GadHelp "Toggle selected lines"
  317.  Gosub #this ToggleSelect
  318.  
  319.  
  320.  
  321. xROUTINE TransformIt
  322.  GuiWindow #this WAIT
  323.  LVUse #this 2
  324.  SetGad #this 2 HIDE
  325.  LVGo first ;EXP000 LVXpos = 0 
  326.  ChCtr = 0
  327.  Ctr = 0
  328.  LVSearch '<table' CI FIRST
  329.  WHILE $$LV.LINE > ''
  330.     Gosub #this TransformLine
  331.     LVUse #this 2
  332.      LVSearch '<table' CI NEXT
  333.  ENDWHILE
  334.  EzReq "Checked $Ctr tables.\n $ChCtr changed" "ok" var
  335.  Gosub #this ShowIt
  336.  
  337. xROUTINE ShowIt
  338.  GuiWindow #this RESUME
  339.  SetGad #this 1 HIDE
  340.  SetGad #this 3 HIDE
  341.  SetGad #this 2 SHOW
  342.  Redraw #this
  343.  LVUse #this 2
  344.  
  345. xROUTINE TransformLine
  346.  TSegmt = ''
  347.  SearchVar LVVar2 '<table' CI first
  348.  PosH = $($$Search.Pos - 1)
  349.  
  350.  WHILE $$Search.Pos > ''
  351.  And $$Search.Pos > $PosH
  352.     ++Ctr
  353.     PosH = $$Search.Pos
  354.     SearchVar LVVar2 '>' CI next
  355.     PosT = $$Search.Pos
  356.     SgLgt = $( $PosT - $PosH + 1 )
  357.     TSegmt = $LVVar2[$PosH][$SgLgt]
  358.     LVMulti ON
  359.     Gosub #this AdaptTableSgmt
  360.     SearchVar LVVar2[$PosT] '<table' CI next
  361.  ENDWHILE
  362.  
  363. xROUTINE GetImageSgmt
  364.  ImSegmt = ''
  365.     LVSearch '<img ' CI next
  366.     IF $$LV.LINE > ''
  367.         LVMULTI ON
  368.         ;NLine = $$LV.LINE
  369.         PosH = $$Search.Pos
  370.         LVSearch '>' CI next
  371.         PosT = $$Search.Pos
  372.         SgLgt = $( $PosT - $PosH + 1 )
  373.         ImSegmt = $LVVar2[$PosH][$SgLgt]
  374.     ELSE
  375.         NoMore = Yes
  376.         RETURN
  377.     ENDIF
  378.  
  379. xROUTINE DeleteImageSgmt
  380. LVline = $LVVar2
  381. RepVar LVline $ImSegmt "" CI
  382. LVPut $LVline
  383. --PosH
  384. LVPos $$LV.Line $PosH  ; does not work EXP
  385.  
  386. xROUTINE DeleteImageSgmt_
  387. LVline = $LVVar2
  388. RepVar LVline $ImSegmt "" CI
  389. LVPut $LVline
  390.  
  391. xROUTINE AdaptTableSgmt
  392.  ;Check if need to be adapted
  393.  ; Set DeepTrans Off
  394.  Searchvar TSegmt width= CI first ;width="95%"; width=100%"
  395.  IF $$Search.Pos > ''
  396.     Pos = $$Search.Pos
  397.     Pos0 = $($Pos + 6) ; begin of 'Width number'
  398.     Wdth = $TSegmt[$Pos0][6] ; "94%" "100%" 640 999 (*)
  399.     RepVar Wdth '"' 'µ' CS ; The '"' and '%' characters  are diffficult characters
  400.     RepVar Wdth "%" "£" CS ; we replace them here with 'normal' characters
  401.     SearchVar Wdth £ CS First
  402.     IF $$Search.Pos = ''   ; % not found, it's a width expressed in absolute value
  403.         IF $Wdth[0][1] = µ  ; it's expresses as "540"
  404.             ; EzReq '$Wdth[1] ??' 'ok' var
  405.             SearchVar Wdth[1] µ CS first ; search for the second µ (")
  406.             Pos2 = $$Search.Pos
  407.             Wdth = $Wdth[1][$Pos2] ; => length - 1
  408.             LgtW = $($Pos2 + 1)
  409.             PutIn = '"$NwWdth"' ; Default value = 450
  410.         ELSE                    ; it's expressed as 540
  411.             Wdth = $Wdth[0][3] ; (*) we don't expect tables from more than 3 digits
  412.                                 ; it might be  =80  (80 ); this does not matter
  413.             LgtW = 3
  414.             PutIn = $NwWdth
  415.         ENDIF
  416.         IF $Wdth > $NwWdth
  417.             NwLVVar2 = $LVVar2
  418.             St = $($PosH + $Pos0 )
  419.             NwLVVar2[$St][$LgtW] = $PutIn ; we replace in situ the width with new width
  420.             LVPut $NwLVVar2
  421.             ++ChCtr
  422.         ENDIF
  423.     ELSE
  424.     ;EzReq "Not transformed" "ok" var
  425.     ENDIF
  426.  ELSE
  427.     ;EzReq "Not transformed" "ok" var
  428.  ENDIf
  429.  
  430.  ;EzReq  "**$Wdth\** \n$LVVar2" "ok|stop" var ; = '%' % = Hex 25
  431.  
  432.  ; Set DeepTrans ON
  433.  
  434. xBUTTON 420 0 60 14 HELP ; <<HELP>>
  435.  GadHelp "..and help will be provided"
  436.  IFEXISTS GUI ~Table.hlp
  437.     GuiLoad guitb:Table.hlp
  438.  ENDIF
  439.      Str1 = "Need more help ?\n"
  440.      Str2 = "Contact me at jduchatelet@arcadis.be"
  441.      EzReq "$.Tb_Goal" "ok|more" var
  442.      IF $var = 0
  443.         EzReq "$.Tb_Start&Usage" "ok|more" var
  444.         IF $var = 0
  445.             EzReq "$.Tb_Start&Usage2" "ok|more" var
  446.             IF $var = 0
  447.                 EzReq "$.Tb_IB_Start" "ok|more" var
  448.                 IF $var = 0
  449.                     EzReq "$.Tb_Extensions" "ok|more" var
  450.                     IF $var = 0
  451.                         EzReq "$.Tb_Lic&Credits" "ok|more" var
  452.                         IF $var = 0
  453.                             EzReq "$Str1\#$Str2" "ok|more" var
  454.                         ENDIF
  455.                     ENDIF
  456.                 ENDIF
  457.             ENDIF
  458.         ENDIF
  459.     ENDIF
  460.  IF $.TbCfg_Help = OFF
  461.     GuiQuit Table.hlp
  462.  ENDIF
  463.  
  464. xBUTTON 480 0 30 14 Off ; <<Off>>
  465.  GadHelp 'Help information not permanently in ram:' 
  466.  LVUse #this 3
  467.  SetGad #this 1 HIDE
  468.  SetGad #this 2 HIDE
  469.  SetGad #this 3 SHOW
  470.  Redraw #this
  471.  LVChange guitb:Table.Cfg
  472.  LVGo #2
  473.  LVPut OFF
  474.  LVSave guitb:Table.Cfg 
  475.  .TbCfg_Help = OFF
  476.  
  477.  
  478. ;xBUTTON 480 0 60 14 Vw3
  479.  ;Gosub #this Show3
  480.  
  481. xROUTINE Show3
  482.  SetGad #this 1 HIDE
  483.  SetGad #this 2 HIDE
  484.  SetGad #this 3 SHOW 
  485.  Redraw #this
  486.  
  487.  
  488. xNOTIFY Sys:Internet/IBrowse/ ON
  489.  LVUse #this 2
  490.  LVClear
  491.  FlNm = APrint.html
  492.  Fl2Tr = Sys:Internet/IBrowse/APrint.html
  493.  INFO FILE $Fl2Tr
  494.  IF $$FILE.DATE = $$SYS.DATE
  495.     ; EzReq "$$FILE.TIME[0][7] = $$SYS.TIME[0][7]" "ok" var    
  496.     IF $$FILE.TIME[0][7] = $$SYS.TIME[0][7]
  497.         LVMode MULTI
  498.         LVChange $Fl2Tr
  499.         CLI 'Faststrip $Fl2Tr 13 10'
  500.         Gosub #this TransformIt
  501.         LVSave ram:APrint.html
  502.         IFEXISTS PORT 'IBROWSE'
  503.             SendRexx IBROWSE 'GOTOURL "file://localhost/ram:APrint.html"'
  504.         ENDIF
  505.     ENDIF
  506.  ENDIF
  507.  
  508. xROUTINE Storage
  509.     ; EzReq "$$FILE.TIME[0][7] = $$SYS.TIME[0][7]" "ok" var
  510.  
  511. xLISTVIEW 0 14 600 200  '' LVVar1  '' 30 MULTI
  512.  GadId 1 
  513.  GadHelp "Shows imagelist"
  514.  
  515. xLISTVIEW 0 14 600 200  '' LVVar2  '' 30 MULTI
  516.  GadId 2 
  517.  GadHelp "Shows html doc to transform"
  518.  
  519. xLISTVIEW 0 14 600 200  '' LVVar3  '' 30 MULTI
  520.  GadId 3 
  521.  ; "working LV"